//
//  BugPigCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/9/9.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "BugPigCell.h"

@implementation BugPigCell

- (void)setupUI{
    
    [self addSubview:self.bgView];
}

- (void)setupLayout{
    
    {
        _bgView.size = CGSizeMake(KScreenWidth - 30, 100);
        _bgView.mj_x = _bgView.mj_y = 15;
    }
    
    {
        _vouchersIcon.size = CGSizeMake(150, 100);
        _vouchersIcon.mj_x = _vouchersIcon.mj_y = 0;
    }
    
    {
        _priceLab.size = CGSizeMake(94, 84);
        _priceLab.mj_x = 28;
        _priceLab.mj_y = 12;
    }
    
    {
        _tipLab.size = CGSizeMake(20, 44);
        _tipLab.mj_x = 10;
        _tipLab.mj_y = 6;
    }
    
    {
        _tipLab1.size = CGSizeMake(100, 22);
        _tipLab1.mj_x = _vouchersIcon.right + 15;
        _tipLab1.mj_y = 10;
    }
    
    {
        _dateLab.size = CGSizeMake(200, 14);
        _dateLab.mj_x = _tipLab1.mj_x;
        _dateLab.mj_y = 66;
    }
    
    {
        _selectedIcon.size = CGSizeMake(18, 18);
        _selectedIcon.mj_x = _bgView.width - _selectedIcon.width - 15;
        _selectedIcon.mj_y = (_bgView.height - _selectedIcon.height)/2.0;
    }
}

#pragma mark - setter methods

- (void)setItem:(DiscountCoupons *)item{
    
    _dateLab.text = [NSString stringWithFormat:@"有效期：%@-%@", item.validStartTime, item.validEndTime];
    _priceLab.text = [NSString stringWithFormat:@"¥ %@", item.couponValue];
    [_vouchersIcon sd_setImageWithURL:[NSURL URLWithString:item.imgName] placeholderImage:[UIImage imageNamed:@"placeholder_small"]];
    _selectedIcon.image = item.isSelect ?[UIImage imageNamed:@"adopt_buy_selected"] :[UIImage imageNamed:@"meat_cart_unchecked"];
}

#pragma mark - getter methods

- (UIView *)bgView{
    
    if (!_bgView) {
        _bgView = [UIView makeViewBgColor:KWhiteColor cornerRadius:4];
        [self addShadowToView:_bgView withColor:UIColorFromRGB(0x3B4A74)];
        
        [_bgView addSubview:self.vouchersIcon];
        [_bgView addSubview:self.selectedIcon];
        [_bgView addSubview:self.tipLab];
        [_bgView addSubview:self.priceLab];
        [_bgView addSubview:self.dateLab];
        [_bgView addSubview:self.tipLab1];

    }
    return _bgView;
}


/// 添加四边阴影效果
- (void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {
    // 阴影颜色
    theView.layer.shadowColor = theColor.CGColor;
    // 阴影偏移，默认(0, -3)
    theView.layer.shadowOffset = CGSizeMake(0,0);
    // 阴影透明度，默认0
    theView.layer.shadowOpacity = 0.5;
    // 阴影半径，默认3
    theView.layer.shadowRadius = 5;
}


- (UILabel *)tipLab{
    
    if (!_tipLab) {
        _tipLab = [UILabel makeLabelWithText:@"豚\n券" textColor:UIColorFromRGB(0x327F60) font:mMediumFont(16) textAliment:0];
        _tipLab.numberOfLines = 0;
    }
    return _tipLab;
}


- (UILabel *)tipLab1{
    
    if (!_tipLab1) {
        _tipLab1 = [UILabel makeLabelWithText:@"新人豚券" textColor:UIColorFromRGB(0x363636) font:mFont(16) textAliment:0];
    }
    return _tipLab1;
}


- (UILabel *)priceLab{
    
    if (!_priceLab) {
        _priceLab = [UILabel makeLabelWithText:@"¥50" textColor:UIColorFromRGB(0x327F60) font:mSemiboldFont(29) textAliment:0];
    }
    return _priceLab;
}


- (UILabel *)dateLab{
    
    if (!_dateLab) {
        _dateLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x363636) font:mFont(10) textAliment:0];
    }
    return _dateLab;
}

- (UIImageView *)vouchersIcon{
    
    if (!_vouchersIcon) {
        _vouchersIcon = [[UIImageView alloc] init];
        
    }
    return _vouchersIcon;
}

- (UIImageView *)selectedIcon{
    
    if (!_selectedIcon) {
        _selectedIcon = [[UIImageView alloc] init];
        _selectedIcon.image = [UIImage imageNamed:@"meat_cart_unchecked"];
    }
    return _selectedIcon;
}

@end
